package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.Group;
import cn.kgc.springcloud.service.GroupService;
import cn.kgc.springcloud.vo.GroupVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author: 课工场
 * @since 2023/9/12
 */
@RestController
@RequestMapping("group")
public class GroupController {

    @Autowired
    private GroupService groupService;

    // 获取小组列表
    @GetMapping("list")
    public List<GroupVO> groupVOList() {

        return groupService.getGroupVOList();
    }

    //添加小组信息
    @PostMapping("add")
    public Group addGroup(@RequestBody Group group) {

        group.setCreatedate(new Date());
        groupService.save(group);
        return group;
    }

    @GetMapping("getById/{id}")
    public Group getById(@PathVariable("id") Integer id) {
        return groupService.getById(id);
    }
}
